package com.kosam.commons.base.exception;

import com.kosam.commons.base.entity.Message;

/**
 * Created by tgx on 2017/2/20.
 */
public class BusinessException extends RuntimeException{

    private static final long serialVersionUID = 1L;

    private String code;
    private String title;
    private String detail;

    public BusinessException() {

    }

    public BusinessException(String code, String title, String detail) {
        super("[" + code + "]" + title);
        this.code = code;
        this.title = title;
        this.detail = detail;
    }

    public BusinessException(String code, String message) {
        super(code + "," + message);
        this.code = code;
    }

    public BusinessException( String message) {
        super(message);
    }
    public BusinessException(Message message) {
        this(message.getCode(), message.getTitle(), message.getDetail());
    }

    public String getCode() {
        return code;
    }

    public String getTitle() {
        return title;
    }

    public String getDetail() {
        return detail;
    }

    public Message buildMessage() {
        return new Message(code, title, detail);
    }


    public BusinessException(Throwable cause, String code) {
        super(cause);
        this.code = code;
    }
}
